package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_PostCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_PostCategoryController {
    @Autowired
    private Ad_PostCategoryService ad_postCategoryService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adPostCategory", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminPostCategory(HttpServletRequest request, @RequestBody DanhMucBaiVietDto postCategoryDto) {
        return new JsonResponseDto<Integer>(ad_postCategoryService.adminPostCategory(postCategoryDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllCategory", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<DanhMucBaiVietDto>> getAllCategory(HttpServletRequest request) {
        return new JsonResponseDto<List<DanhMucBaiVietDto>>(ad_postCategoryService.getAllCategory(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toPostCategoryPage/{maDMBV}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductCategory(HttpServletRequest request, @PathVariable String maDMBV, Map<String, Object> map) throws ParseException {
        map.put("maDMBV", maDMBV);
        return new ModelAndView("admin/ad-post-category-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editPostCategory", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<DanhMucBaiVietDto> getPostCategoryInfoEdit(HttpServletRequest request, @RequestBody DanhMucBaiVietDto categoryDto) {
        return new JsonResponseDto<DanhMucBaiVietDto>(ad_postCategoryService.getPostCategoryInfoEdit(categoryDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerPostCategoryEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<DanhMucBaiVietDto> registerPostCategoryEdit(HttpServletRequest request, @RequestBody DanhMucBaiVietDto categoryDto) {
        return new JsonResponseDto<DanhMucBaiVietDto>(ad_postCategoryService.registerPostCategoryEdit(categoryDto), JsonResponseCode.SUCCESS);
    }
}
